package com.rogue.order.seckill.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rogue.order.seckill.domain.CouponDTO;
import com.rogue.order.seckill.domain.HsCoupon;
import com.rogue.order.seckill.mapper.HsCouponMapper;
import com.rogue.order.seckill.service.HsCouponService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
* @author YeahLiang
* @description 针对表【hs_coupon(优惠券表)】的数据库操作Service实现
* @createDate 2022-03-16 15:42:40
*/
@Service
public class HsCouponServiceImpl extends ServiceImpl<HsCouponMapper, HsCoupon>
    implements HsCouponService{

    @Resource
    private HsCouponMapper hsCouponMapper;

    @Override
    public PageInfo listCoupon(CouponDTO couponDTO) {

        final PageInfo<HsCoupon> pageInfo = PageHelper.startPage(couponDTO.getPage(), couponDTO.getCount()).doSelectPageInfo(() ->
                hsCouponMapper.selectList(new LambdaQueryWrapper<HsCoupon>()
                        .eq(Objects.nonNull(couponDTO.getCouponType()), HsCoupon::getCouponType, couponDTO.getCouponType())
                        .eq(Objects.nonNull(couponDTO.getType()), HsCoupon::getType, couponDTO.getType())
                        .eq(Objects.nonNull(couponDTO.getCouponStatus()), HsCoupon::getCouponStatus, couponDTO.getCouponStatus())
                        .like(StrUtil.isNotBlank(couponDTO.getName()), HsCoupon::getName, couponDTO.getName())
                ));
        return pageInfo;
    }
}




